package com.example.perpetualcalendar.ui.fragment.almanac;


import androidx.annotation.NonNull;
import androidx.lifecycle.Observer;

import com.example.perpetualcalendar.R;
import com.example.perpetualcalendar.base.BaseFragment;
import com.example.perpetualcalendar.databinding.FragmentDashboardBinding;
import com.example.perpetualcalendar.domain.entity.Almanac;


/**
 * @author langhua
 */
public class AlmanacFragment extends BaseFragment<AlmanacViewModel,FragmentDashboardBinding> {


    @Override
    protected void initView() {
        mViewModel.getDto().observe(getViewLifecycleOwner(), new Observer<Almanac.ResultDTO>() {
            @Override
            public void onChanged(Almanac.ResultDTO resultDTO) {
                viewBinding.textWuxing.setText(resultDTO.getWuxing());
                viewBinding.textChongsha.setText(resultDTO.getChongsha());
                viewBinding.textJsyq.setText(resultDTO.getJishen());
                viewBinding.textXsyj.setText(resultDTO.getXiongshen());
                viewBinding.textPzbj.setText(resultDTO.getBaiji());
            }
        });
        viewBinding.calendarView.setOnDateChangeListener((view, year, month, dayOfMonth) -> {
            mViewModel.almanac(year+"-"+(month+1)+"-"+dayOfMonth);
        });
    }

    @NonNull
    @Override
    protected Class<AlmanacViewModel> setViewModel() {
        return AlmanacViewModel.class;
    }

    @NonNull
    @Override
    protected int setLayout() {
        return R.layout.fragment_dashboard;
    }
}